home *** CD-ROM | disk | FTP | other *** search
/ Revolution - Das Atari CD Magazin 1997 / Revolution - Das Atari CD Magazin 1.iso / software / progtool / olga / olga.lzh / source / OLGA.PAS < prev   
Pascal/Delphi Source File  |  1996-11-20  |  47KB  |  2,114 lines

  1. {***************************************
  2.  * Object Linking for GEM Applications *
  3.  *       written by Thomas Much        *
  4.  ***************************************
  5.  *      O L G A - M a n a g e r        *
  6.  *   Dieses Programm ist Freeware!     *
  7.  ***************************************
  8.  *    Thomas Much, Gerwigstraße 46,    *
  9.  * 76131 Karlsruhe, Fax (0721) 622821  *
  10.  *         Thomas Much @ KA2           *
  11.  *  Thomas.Much@stud.uni-karlsruhe.de  *
  12.  ***************************************
  13.  *    erstellt am:        07.03.1995   *
  14.  *    letztes Update am:  20.11.1996   *
  15.  ***************************************}
  16.  
  17. {$IFDEF DEBUG}
  18.     {$B+,D+,G-,I-,L+,N-,P-,Q+,R+,S+,T-,V-,X+,Z-}
  19. {$ELSE}
  20.     {$B+,D-,G-,I-,L-,N-,P-,Q-,R-,S-,T-,V-,X+,Z-}
  21. {$ENDIF}
  22.  
  23. {$M 16384}
  24.  
  25. program OLGA;
  26.  
  27. uses
  28.  
  29.     Strings,Dos,Tos,Gem;
  30.  
  31. const
  32.  
  33.     OLGAVersion      = $0120;
  34.     OLGAVersionStr   = '1.20';
  35.     OLGARevision     = '1.2';
  36.     OLGADate         = '20.11.96';
  37.     OLGAProtocol     = 0;
  38.  
  39.     {$I OLGA.INC}
  40.  
  41. const
  42.  
  43.     OLGAFlags        = OL_MANAGER or OL_START or OL_IDLE;
  44.     CMDMAX           =     9;
  45.     SIGQUIT          =     3;
  46.     SIGTERM          =    15;
  47.     CH_EXIT          =    90;
  48.     WF_WINX          = 22360;
  49.     AV_SENDKEY       = $4710;
  50.     VA_START         = $4711;
  51.     AV_PATH_UPDATE   = $4730;
  52.     GLOBAL           =   $20;
  53.     _p_cookies       =  $5a0;
  54.     _bootdev         =  $446;
  55.  
  56. type
  57.  
  58.     PLongint = ^longint;
  59.     PWord    = ^word;
  60.  
  61.     PCookie = ^TCookie;
  62.     TCookie = record
  63.         ID:  array[0..3] of char;
  64.         Val: longint
  65.     end;
  66.  
  67.     PLink = ^TLink;
  68.     TLink = record
  69.         apID,
  70.         Group: integer;
  71.         Path : pointer;
  72.         Prev,
  73.         Next : PLink
  74.     end;
  75.  
  76.     PDocument = ^TDocument;
  77.     TDocument = record
  78.         apID,
  79.         Group: integer;
  80.         Prev,
  81.         Next : PDocument
  82.     end;
  83.  
  84.     PNote = ^TNote;
  85.     TNote = record
  86.         apID,
  87.         ext4,
  88.         ext5: integer;
  89.         Prev,
  90.         Next: PNote
  91.     end;
  92.     
  93.     PClient = ^TClient;
  94.     TClient = record
  95.         srvID,
  96.         clID : integer;
  97.         Prev,
  98.         Next : PClient
  99.     end;
  100.     
  101.     PServer = ^TServer;
  102.     TServer = record
  103.         clID,
  104.         srvID,
  105.         ext4,
  106.         ext5 : integer;
  107.         Prev,
  108.         Next : PServer
  109.     end;
  110.  
  111.     PObject = ^TObject;
  112.     TObject = record
  113.         ext4,
  114.         ext5 : integer;
  115.         descr: pointer;
  116.         next : PObject
  117.     end;
  118.  
  119.     PApp = ^TApp;
  120.     TApp = record
  121.         apID,
  122.         Protocol,
  123.         ipaProtocol,
  124.         Flags,
  125.         XAccType,
  126.         CmdCount   : integer;
  127.         CmdLen     : array [0..CMDMAX] of integer;
  128.         StartCmd   : array [0..CMDMAX] of pointer;
  129.         enumOLE    : PObject;
  130.         Prev,
  131.         Next       : PApp
  132.     end;
  133.  
  134.     PType = ^TType;
  135.     TType = record
  136.         typ : integer;
  137.         path: string;
  138.         next: PType
  139.     end;
  140.  
  141.     PExtension = ^TExtension;
  142.     TExtension = record
  143.         ext4,
  144.         ext5: integer;
  145.         path: string;
  146.         next: PExtension
  147.     end;
  148.  
  149.     PAlias = ^TAlias;
  150.     TAlias = record
  151.         alias,
  152.         path : string;
  153.         next : PAlias
  154.     end;
  155.  
  156.     PAESVARS = ^AESVARS;
  157.     AESVARS  = record
  158.         magic      : longint;
  159.         membot,
  160.         aes_start  : pointer;
  161.         magic2     : array [0..3] of char;
  162.         date       : longint;
  163.         chgres,
  164.         shel_vector,
  165.         aes_bootdrv,
  166.         vdi_device : pointer;
  167.         reservd1,
  168.         reservd2,
  169.         reservd3   : pointer;
  170.         version,
  171.         release    : integer
  172.     end;
  173.  
  174.     PMAGX_COOKIE = ^MAGX_COOKIE;
  175.     MAGX_COOKIE  = record
  176.         config_status: longint;
  177.         dos_vars     : pointer;
  178.         aes_vars     : PAESVARS
  179.     end;
  180.  
  181. var
  182.  
  183.     apID,
  184.     menuID,
  185.     LinkCount,
  186.     AppCount,
  187.     DocCount     : integer;
  188.     termflag,
  189.     MultiTOS,
  190.     Multitask,
  191.     MemProt,
  192.     MagiX,
  193.     has_agi,
  194.     mbar         : boolean;
  195.     empty        : pointer;
  196.     Apps         : PApp;
  197.     Links        : PLink;
  198.     Docs         : PDocument;
  199.     Aliases      : PAlias;
  200.     Types        : PType;
  201.     Notes        : PNote;
  202.     Server       : PServer;
  203.     Clients      : PClient;
  204.     Objects      : PObject;
  205.     Extensions   : PExtension;
  206.     apName       : PChar;
  207.  
  208.  
  209.  
  210. function HeapFunc(size: longint): integer;
  211.  
  212.   begin
  213.     HeapFunc:=1
  214.   end;
  215.  
  216.  
  217. procedure SigHandler(dummy1,dummy2,sig: pointer);
  218.  
  219.     begin
  220.         termflag:=true
  221.     end;
  222.  
  223.  
  224. function bootdev: longint;
  225.  
  226.     begin
  227.         bootdev:=PWord(_bootdev)^+65
  228.     end;
  229.  
  230.  
  231. function ltoa(x: longint): string;
  232.     var dummy: string;
  233.  
  234.     begin
  235.         str(x,dummy);
  236.         ltoa:=dummy
  237.     end;
  238.  
  239.  
  240. function StrPPas(p: PChar): string;
  241.  
  242.     begin
  243.         if p=nil then StrPPas:=''
  244.         else
  245.             StrPPas:=StrPas(p)
  246.     end;
  247.  
  248.  
  249. function Ptr(hi,lo: word): pointer;
  250.  
  251.     begin
  252.         Ptr:=pointer(longint(hi)*longint(65536)+longint(lo))
  253.     end;
  254.  
  255.  
  256. function HiWord(p: pointer): word;
  257.  
  258.     begin
  259.         HiWord:=word(longint(p) div 65536)
  260.     end;
  261.  
  262.  
  263. function LoWord(p: pointer): word;
  264.  
  265.     begin
  266.         LoWord:=word(longint(p) mod 65536)
  267.     end;
  268.  
  269.  
  270. function bTst(value,mask: longint): boolean;
  271.  
  272.     begin
  273.         bTst:=((value and mask)=mask)
  274.     end;
  275.  
  276.  
  277. procedure GlobalAlloc(var p: pointer; size: longint);
  278.  
  279.     begin
  280.         if MemProt then p:=mxalloc(size,GLOBAL)
  281.         else
  282.             getmem(p,size)
  283.     end;
  284.  
  285.  
  286. procedure GlobalFree(var p: pointer; size: longint);
  287.  
  288.     begin
  289.         if p=nil then exit;
  290.         if not(MemProt) then
  291.             begin
  292.                 freemem(p,size);
  293.                 p:=nil
  294.             end
  295.         else
  296.             if mfree(p)=0 then p:=nil
  297.     end;
  298.  
  299.  
  300. function ExpandPath(s: string): string;
  301.     var pal: PAlias;
  302.  
  303.     begin
  304.         if length(s)>0 then
  305.             if s[1]='$' then
  306.                 begin
  307.                     s:=copy(s,2,length(s)-1);
  308.                     pal:=Aliases;
  309.                     while pal<>nil do
  310.                         begin
  311.                             if s=pal^.alias then
  312.                                 begin
  313.                                     ExpandPath:=ExpandPath(pal^.path);
  314.                                     exit
  315.                                 end;
  316.                             pal:=pal^.next
  317.                         end;
  318.                     s:=''
  319.                 end;
  320.         ExpandPath:=s
  321.     end;
  322.  
  323.  
  324. procedure OpenDoc(const pipe: ARRAY_8);
  325.     var pdoc,pdocd: PDocument;
  326.  
  327.     begin
  328.         new(pdoc);
  329.         if pdoc<>nil then
  330.             begin
  331.                 pdoc^.apID:=pipe[1];
  332.                 pdoc^.Group:=pipe[5];
  333.                 pdoc^.Prev:=nil;
  334.                 pdoc^.Next:=nil;
  335.                 if Docs=nil then Docs:=pdoc
  336.                 else
  337.                     begin
  338.                         pdocd:=Docs;
  339.                         while pdocd^.Next<>nil do pdocd:=pdocd^.Next;
  340.                         pdocd^.Next:=pdoc;
  341.                         pdoc^.Prev:=pdocd
  342.                     end;
  343.                 inc(DocCount)
  344.             end
  345.     end;
  346.  
  347.  
  348. procedure Denotify(orgID,e4,e5: integer);
  349.     label _nochmal;
  350.  
  351.     var pn: PNote;
  352.  
  353.     begin
  354.         _nochmal:
  355.         pn:=Notes;
  356.         while pn<>nil do
  357.             begin
  358.                 if orgID=pn^.apID then
  359.                     if ((e4=pn^.ext4) and (e5=pn^.ext5)) or ((e4=0) and (e5=0)) then
  360.                         begin
  361.                             if (pn^.Prev=nil) and (pn^.Next=nil) then Notes:=nil
  362.                             else
  363.                                 begin
  364.                                     if pn^.Prev=nil then Notes:=pn^.Next
  365.                                     else
  366.                                         pn^.Prev^.Next:=pn^.Next;
  367.                                     if pn^.Next<>nil then pn^.Next^.Prev:=pn^.Prev
  368.                                 end;
  369.                             dispose(pn);
  370.                             goto _nochmal
  371.                         end;
  372.                 pn:=pn^.Next
  373.             end
  374.     end;
  375.  
  376.  
  377. function Unlink(pv,gv: boolean; const pipe: ARRAY_8): integer;
  378.     label _unlink,_weiter;
  379.  
  380.     var pc : PChar;
  381.         pld: PLink;
  382.         ret: integer;
  383.  
  384.     begin
  385.         if pv then pc:=PChar(Ptr(word(pipe[3]),word(pipe[4])));
  386.         Unlink:=0;
  387.         ret:=0;
  388.         _unlink:
  389.         pld:=Links;
  390.         while pld<>nil do
  391.             with pld^ do
  392.                 begin
  393.                     if apID=pipe[1] then
  394.                         begin
  395.                             if gv then
  396.                                 if Group<>pipe[5] then goto _weiter;
  397.                             if pv then
  398.                                 if StrIComp(pc,Path)<>0 then goto _weiter;
  399.                             GlobalFree(Path,StrLen(Path)+1);
  400.                             if (Prev=nil) and (Next=nil) then Links:=nil
  401.                             else
  402.                                 begin
  403.                                     if Prev=nil then Links:=Next
  404.                                     else
  405.                                         Prev^.Next:=Next;
  406.                                     if Next<>nil then Next^.Prev:=Prev
  407.                                 end;
  408.                             dispose(pld);
  409.                             dec(LinkCount);
  410.                             if pv then
  411.                                 begin
  412.                                     inc(ret);
  413.                                     Unlink:=ret
  414.                                 end;
  415.                             goto _unlink
  416.                         end;
  417.                     _weiter:
  418.                     pld:=Next
  419.                 end
  420.     end;
  421.  
  422.  
  423. procedure CloseDoc(gv: boolean; const pipe: ARRAY_8);
  424.     label _closedoc,_weiter;
  425.  
  426.     var pdocd: PDocument;
  427.  
  428.     begin
  429.         _closedoc:
  430.         pdocd:=Docs;
  431.         while pdocd<>nil do
  432.             with pdocd^ do
  433.                 begin
  434.                     if apID=pipe[1] then
  435.                         begin
  436.                             if gv then
  437.                                 if Group<>pipe[5] then goto _weiter;
  438.                             if (Prev=nil) and (Next=nil) then Docs:=nil
  439.                             else
  440.                                 begin
  441.                                     if Prev=nil then Docs:=Next
  442.                                     else
  443.                                         Prev^.Next:=Next;
  444.                                     if Next<>nil then Next^.Prev:=Prev
  445.                                 end;
  446.                             dispose(pdocd);
  447.                             dec(DocCount);
  448.                             goto _closedoc
  449.                         end;
  450.                     _weiter:
  451.                     pdocd:=Next
  452.                 end
  453.     end;
  454.  
  455.  
  456. function ShelWrite(mode,wisgr,wiscr: integer; cmd,tail: pointer): integer;
  457.  
  458.     begin
  459.         with AES_pb do
  460.             begin
  461.                 control^[0]:=121;
  462.                 control^[1]:=3;
  463.                 control^[2]:=1;
  464.                 control^[3]:=2;
  465.                 control^[4]:=0;
  466.                 intin^[0]:=mode;
  467.                 intin^[1]:=wisgr;
  468.                 intin^[2]:=wiscr;
  469.                 addrin^[0]:=cmd;
  470.                 addrin^[1]:=tail;
  471.                 _crystal(@AES_pb);
  472.                 if intout^[0]<>0 then ShelWrite:=1
  473.                 else
  474.                     ShelWrite:=0
  475.             end
  476.     end;
  477.  
  478.  
  479. function appl_xgetinfo(ap_gtype: integer; var ap_gout1,ap_gout2,ap_gout3,ap_gout4: integer): boolean;
  480.  
  481.     begin
  482.         appl_xgetinfo:=false;
  483.         if has_agi then
  484.             with AES_pb do
  485.                 begin
  486.                     control^[0]:=130;
  487.                     control^[1]:=1;
  488.                     control^[2]:=5;
  489.                     control^[3]:=0;
  490.                     control^[4]:=0;
  491.                     intin^[0]:=ap_gtype;
  492.                     _crystal(@AES_pb);
  493.                     if intout^[0]=1 then
  494.                         begin
  495.                             ap_gout1:=intout^[1];
  496.                             ap_gout2:=intout^[2];
  497.                             ap_gout3:=intout^[3];
  498.                             ap_gout4:=intout^[4];
  499.                             appl_xgetinfo:=true
  500.                         end
  501.                 end
  502.     end;
  503.  
  504.  
  505. function getjar: longint;
  506.  
  507.     begin
  508.         getjar:=PLongint(_p_cookies)^
  509.     end;
  510.  
  511.  
  512. procedure ServerStarted(srvID,clID,ext4,ext5: integer);
  513.     var ps,psd: PServer;
  514.         pc,pcd: PClient;
  515.         found : boolean;
  516.  
  517.     begin
  518.         ps:=Server;
  519.         found:=false;
  520.         while ps<>nil do
  521.             begin
  522.                 if clID=ps^.clID then
  523.                     if srvID=ps^.srvID then
  524.                         if (ext4=ps^.ext4) and (ext5=ps^.ext5) then
  525.                             begin
  526.                                 found:=true;
  527.                                 break
  528.                             end;
  529.                 ps:=ps^.Next;
  530.             end;
  531.         if not(found) then
  532.             begin
  533.                 new(ps);
  534.                 if ps<>nil then
  535.                     begin
  536.                         ps^.clID:=clID;
  537.                         ps^.srvID:=srvID;
  538.                         ps^.ext4:=ext4;
  539.                         ps^.ext5:=ext5;
  540.                         ps^.Prev:=nil;
  541.                         ps^.Next:=nil;
  542.                         if Server=nil then Server:=ps
  543.                         else
  544.                             begin
  545.                                 psd:=Server;
  546.                                 while psd^.Next<>nil do psd:=psd^.Next;
  547.                                 psd^.Next:=ps;
  548.                                 ps^.Prev:=psd
  549.                             end
  550.                     end
  551.             end;
  552.         pc:=Clients;
  553.         found:=false;
  554.         while pc<>nil do
  555.             begin
  556.                 if pc^.srvID=srvID then
  557.                     if pc^.clID=clID then
  558.                         begin
  559.                             found:=true;
  560.                             break
  561.                         end;
  562.                 pc:=pc^.Next
  563.             end;
  564.         if not(found) then
  565.             begin
  566.                 new(pc);
  567.                 if pc<>nil then
  568.                     begin
  569.                         pc^.srvID:=srvID;
  570.                         pc^.clID:=clID;
  571.                         pc^.Prev:=nil;
  572.                         pc^.Next:=nil;
  573.                         if Clients=nil then Clients:=pc
  574.                         else
  575.                             begin
  576.                                 pcd:=Clients;
  577.                                 while pcd^.Next<>nil do pcd:=pcd^.Next;
  578.                                 pcd^.Next:=pc;
  579.                                 pc^.Prev:=pcd
  580.                             end
  581.                     end
  582.             end
  583.     end;
  584.  
  585.  
  586. procedure ClientTerminated(clID: integer);
  587.     label _nochmal;
  588.     
  589.     var answ  : ARRAY_8;
  590.         pc,pcd: PClient;
  591.  
  592.     begin
  593.         answ[0]:=OLGA_CLIENTTERMINATED;
  594.         answ[1]:=apID;
  595.         answ[2]:=0;
  596.         answ[3]:=clID;
  597.         answ[5]:=0;
  598.         answ[6]:=0;
  599.         answ[7]:=0;
  600.         _nochmal:
  601.         pc:=Clients;
  602.         while pc<>nil do
  603.             begin
  604.                 if pc^.clID=clID then
  605.                     begin
  606.                         answ[4]:=0;
  607.                         pcd:=Clients;
  608.                         while pcd<>nil do
  609.                             begin
  610.                                 if pcd<>pc then
  611.                                     if pcd^.srvID=pc^.srvID then inc(answ[4]);
  612.                                 pcd:=pcd^.Next
  613.                             end;
  614.                         appl_write(pc^.srvID,16,@answ);
  615.                         if (pc^.Prev=nil) and (pc^.Next=nil) then Clients:=nil
  616.                         else
  617.                             begin
  618.                                 if pc^.Prev=nil then Clients:=pc^.Next
  619.                                 else
  620.                                     pc^.Prev^.Next:=pc^.Next;
  621.                                 if pc^.Next<>nil then pc^.Next^.Prev:=pc^.Prev
  622.                             end;
  623.                         dispose(pc);
  624.                         goto _nochmal
  625.                     end
  626.                 else
  627.                     if pc^.srvID=clID then
  628.                         begin
  629.                             if (pc^.Prev=nil) and (pc^.Next=nil) then Clients:=nil
  630.                             else
  631.                                 begin
  632.                                     if pc^.Prev=nil then Clients:=pc^.Next
  633.                                     else
  634.                                         pc^.Prev^.Next:=pc^.Next;
  635.                                     if pc^.Next<>nil then pc^.Next^.Prev:=pc^.Prev
  636.                                 end;
  637.                             dispose(pc);
  638.                             goto _nochmal
  639.                         end;
  640.                 pc:=pc^.Next
  641.             end
  642.     end;
  643.  
  644.  
  645. procedure ServerTerminated(srvID,retCode: integer);
  646.     label _nochmal;
  647.     
  648.     var ps  : PServer;
  649.         answ: ARRAY_8;
  650.  
  651.     begin
  652.         answ[0]:=OLGA_SERVERTERMINATED;
  653.         answ[1]:=apID;
  654.         answ[2]:=0;
  655.         answ[3]:=srvID;
  656.         answ[6]:=retCode;
  657.         answ[7]:=0;
  658.         _nochmal:
  659.         ps:=Server;
  660.         while ps<>nil do
  661.             begin
  662.                 if ps^.srvID=srvID then
  663.                     begin
  664.                         answ[4]:=ps^.ext4;
  665.                         answ[5]:=ps^.ext5;
  666.                         appl_write(ps^.clID,16,@answ);
  667.                         if (ps^.Prev=nil) and (ps^.Next=nil) then Server:=nil
  668.                         else
  669.                             begin
  670.                                 if ps^.Prev=nil then Server:=ps^.Next
  671.                                 else
  672.                                     ps^.Prev^.Next:=ps^.Next;
  673.                                 if ps^.Next<>nil then ps^.Next^.Prev:=ps^.Prev
  674.                             end;
  675.                         dispose(ps);
  676.                         goto _nochmal
  677.                     end
  678.                 else
  679.                     if ps^.clID=srvID then
  680.                         begin
  681.                             if (ps^.Prev=nil) and (ps^.Next=nil) then Server:=nil
  682.                             else
  683.                                 begin
  684.                                     if ps^.Prev=nil then Server:=ps^.Next
  685.                                     else
  686.                                         ps^.Prev^.Next:=ps^.Next;
  687.                                     if ps^.Next<>nil then ps^.Next^.Prev:=ps^.Prev
  688.                                 end;
  689.                             dispose(ps);
  690.                             goto _nochmal
  691.                         end;
  692.                 ps:=ps^.Next
  693.             end
  694.     end;
  695.  
  696.  
  697. procedure OLEInit(const pipe: ARRAY_8);
  698.     label _nooep;
  699.  
  700.     var answ  : ARRAY_8;
  701.         pa,pad: PApp;
  702.         i     : integer;
  703.  
  704.     begin
  705.         {$IFDEF DEBUG}
  706.         write('OLGA: OLE_INIT App ',pipe[1],'  ');
  707.         if (pipe[3] and OL_SERVER)>0 then write('Server ');
  708.         if (pipe[3] and OL_CLIENT)>0 then write('Client ');
  709.         if (pipe[3] and OL_PIPES)>0 then write('Pipes ');
  710.         write('Stufe ',pipe[4],'  OEP ',pipe[5],' ',pipe[6],'  ');
  711.         writeln(chr(hi(pipe[7])),chr(lo(pipe[7])));
  712.         {$ENDIF}
  713.         if (pipe[3] and OL_PEER)=0 then
  714.             begin
  715.                 answ[7]:=0;
  716.                 goto _nooep
  717.             end;
  718.         pa:=nil;
  719.         pad:=Apps;
  720.         while pad<>nil do
  721.             begin
  722.                 if pad^.apID=pipe[1] then
  723.                     begin
  724.                         pa:=pad;
  725.                         break
  726.                     end;
  727.                 pad:=pad^.Next
  728.             end;
  729.         if pa=nil then
  730.             begin
  731.                 new(pa);
  732.                 if pa<>nil then
  733.                     begin
  734.                         pa^.apID:=pipe[1];
  735.                         pa^.CmdCount:=-1;
  736.                         for i:=0 to CMDMAX do pa^.StartCmd[i]:=nil;
  737.                         pa^.enumOLE:=nil;
  738.                         pa^.ipaProtocol:=0;
  739.                     pa^.Prev:=nil;
  740.                     pa^.Next:=nil;
  741.                         if Apps=nil then Apps:=pa
  742.                         else
  743.                             begin
  744.                                 pad:=Apps;
  745.                                 while pad^.Next<>nil do pad:=pad^.Next;
  746.                                 pad^.Next:=pa;
  747.                                 pa^.Prev:=pad
  748.                             end;
  749.                         inc(AppCount)
  750.                     end
  751.             end;
  752.         if pa<>nil then
  753.             begin
  754.                 pa^.Flags:=pipe[3];
  755.                 pa^.Protocol:=pipe[4];
  756.                 pa^.XAccType:=pipe[7];
  757.                 answ[7]:=1
  758.             end
  759.         else
  760.             answ[7]:=0;
  761.         _nooep:
  762.         answ[0]:=OLGA_INIT;
  763.         answ[1]:=apID;
  764.         answ[2]:=0;
  765.         answ[3]:=OLGAFlags;
  766.         answ[4]:=OLGAProtocol;
  767.         answ[5]:=0;
  768.         answ[6]:=0;
  769.         appl_write(pipe[1],16,@answ)
  770.     end;
  771.  
  772.  
  773. procedure OLEExit(const pipe: ARRAY_8);
  774.     label _exit;
  775.     
  776.     var i     : integer;
  777.         pa,pad: PApp;
  778.         dummy : string;
  779.  
  780.     begin
  781.         {$IFDEF DEBUG}
  782.         writeln('OLGA: OLE_EXIT App ',pipe[1]);
  783.         {$ENDIF}
  784.         Denotify(pipe[1],0,0);
  785.         Unlink(false,false,pipe);
  786.         CloseDoc(false,pipe);
  787.         ServerTerminated(pipe[1],0);
  788.         ClientTerminated(pipe[1]);
  789.         _exit:
  790.         pad:=Apps;
  791.         while pad<>nil do
  792.             with pad^ do
  793.                 begin
  794.                     if apID=pipe[1] then
  795.                         begin
  796.                             for i:=0 to CMDMAX do
  797.                                 if StartCmd[i]<>nil then GlobalFree(StartCmd[i],CmdLen[i]);
  798.                             if (Prev=nil) and (Next=nil) then Apps:=nil
  799.                             else
  800.                                 begin
  801.                                     if Prev=nil then Apps:=Next
  802.                                     else
  803.                                         Prev^.Next:=Next;
  804.                                     if Next<>nil then Next^.Prev:=Prev
  805.                                 end;
  806.                             dispose(pad);
  807.                             dec(AppCount);
  808.                             goto _exit
  809.                         end;
  810.                     pad:=Next
  811.                 end;
  812.         if AppCount=0 then
  813.             if Multitask then
  814.                 if AppFlag then
  815.                     if apName<>nil then
  816.                         begin
  817.                             dummy:=GetEnv('OLGAMANAGER')+#0;
  818.                             if StrIComp(apName,@dummy[1])=0 then
  819.                                 begin
  820.                                     {$IFDEF DEBUG}
  821.                                     writeln('... OLGA deaktiviert.');
  822.                                     {$ENDIF}
  823.                                     appl_exit;
  824.                                     halt
  825.                                 end
  826.                         end
  827.     end;
  828.  
  829.  
  830. procedure OLGAUpdate(const pipe: ARRAY_8);
  831.     var answ : ARRAY_8;
  832.         p2   : pointer;
  833.         pc,p1: PChar;
  834.         pld  : PLink;
  835.         pn   : PNote;
  836.         e4,e5: integer;
  837.         s    : string;
  838.  
  839.     begin
  840.         {$IFDEF DEBUG}
  841.         write('OLGA: OLGA_UPDATE App ',pipe[1],'  ');
  842.         {$ENDIF}
  843.         answ[0]:=OLGA_UPDATED;
  844.         answ[1]:=apID;
  845.         answ[2]:=0;
  846.         answ[5]:=pipe[5];
  847.         answ[6]:=pipe[1];
  848.         pc:=PChar(Ptr(word(pipe[3]),word(pipe[4])));
  849.         {$IFDEF DEBUG}
  850.         writeln(pc,'  Info ',pipe[5]);
  851.         {$ENDIF}
  852.         pld:=Links;
  853.         while pld<>nil do
  854.             with pld^ do
  855.                 begin
  856.                     if StrIComp(pc,Path)=0 then
  857.                         begin
  858.                             {$IFDEF DEBUG}
  859.                             writeln('      Update an App ',apID,' Gruppe ',Group);
  860.                             {$ENDIF}
  861.                             answ[3]:=integer(HiWord(Path));
  862.                             answ[4]:=integer(LoWord(Path));
  863.                             answ[7]:=Group;
  864.                             appl_write(apID,16,@answ)
  865.                         end;
  866.                     pld:=Next
  867.                 end;
  868.         if Notes<>nil then
  869.             begin
  870.                 p1:=StrRScan(pc,'.');
  871.                 p2:=StrRScan(pc,'\');
  872.                 if longint(p1)>longint(p2) then
  873.                     begin
  874.                         s:=StrPas(p1);
  875.                         while length(s)<4 do s:=s+#0;
  876.                         e4:=(ord(s[1]) shl 8) or ord(s[2]);
  877.                         e5:=(ord(s[3]) shl 8) or ord(s[4])
  878.                     end
  879.                 else
  880.                     begin
  881.                         e4:=0;
  882.                         e5:=0
  883.                     end;
  884.                 answ[0]:=OLGA_NOTIFY;
  885.                 answ[5]:=0;
  886.                 answ[6]:=0;
  887.                 answ[7]:=0;
  888.                 pn:=Notes;
  889.                 while pn<>nil do
  890.                     begin
  891.                         if ((e4=pn^.ext4) and (e5=pn^.ext5)) or ((pn^.ext4=0) and (pn^.ext5=0)) then
  892.                             begin
  893.                                 {$IFDEF DEBUG}
  894.                                 writeln('      Notify an App ',pn^.apID);
  895.                                 {$ENDIF}
  896.                                 GlobalAlloc(p2,StrLen(pc)+1);
  897.                                 if p2<>nil then
  898.                                     begin
  899.                                         StrCopy(p2,pc);
  900.                                         answ[3]:=integer(HiWord(p2));
  901.                                         answ[4]:=integer(LoWord(p2));
  902.                                         appl_write(pn^.apID,16,@answ)
  903.                                     end
  904.                             end;
  905.                         pn:=pn^.Next
  906.                     end
  907.             end;
  908.         answ[0]:=OLGA_ACK;
  909.         answ[3]:=pipe[3];
  910.         answ[4]:=pipe[4];
  911.         answ[5]:=0;
  912.         answ[6]:=0;
  913.         answ[7]:=OLGA_UPDATE;
  914.         appl_write(pipe[1],16,@answ)
  915.     end;
  916.  
  917.  
  918. procedure OLGARename(const pipe: ARRAY_8);
  919.     var answ: ARRAY_8;
  920.         pld : PLink;
  921.         pc  : PChar;
  922.  
  923.     begin
  924.         {$IFDEF DEBUG}
  925.         writeln('OLGA: OLGA_RENAME App ',pipe[1],'  ',PChar(Ptr(word(pipe[3]),word(pipe[4]))),' -> ',PChar(Ptr(word(pipe[5]),word(pipe[6]))));
  926.         {$ENDIF}
  927.         pld:=Links;
  928.         answ[0]:=OLGA_RENAMELINK;
  929.         answ[1]:=apID;
  930.         answ[2]:=0;
  931.         answ[5]:=pipe[5];
  932.         answ[6]:=pipe[6];
  933.         pc:=PChar(Ptr(word(pipe[3]),word(pipe[4])));
  934.         while pld<>nil do
  935.             with pld^ do
  936.                 begin
  937.                     if StrIComp(pc,Path)=0 then
  938.                         begin
  939.                             {$IFDEF DEBUG}
  940.                             writeln('      RenameLink an App ',apID,' Gruppe ',Group);
  941.                             {$ENDIF}
  942.                             answ[3]:=integer(HiWord(Path));
  943.                             answ[4]:=integer(LoWord(Path));
  944.                             answ[7]:=Group;
  945.                             appl_write(apID,16,@answ)
  946.                         end;
  947.                     pld:=Next
  948.                 end;
  949.         answ[0]:=OLGA_ACK;
  950.         answ[3]:=pipe[3];
  951.         answ[4]:=pipe[4];
  952.         answ[7]:=OLGA_RENAME;
  953.         appl_write(pipe[1],16,@answ)
  954.     end;
  955.  
  956.  
  957. procedure OLGALinkRenamed(const pipe: ARRAY_8);
  958.     var pld   : PLink;
  959.         pc,pc2: PChar;
  960.         p2    : pointer;
  961.  
  962.     begin
  963.         {$IFDEF DEBUG}
  964.         writeln('OLGA: OLGA_LINKRENAMED App ',pipe[1],' Gruppe ',pipe[7],'  ',PChar(Ptr(word(pipe[3]),word(pipe[4]))),' -> ',PChar(Ptr(word(pipe[5]),word(pipe[6]))));
  965.         {$ENDIF}
  966.         pld:=Links;
  967.         pc:=PChar(Ptr(word(pipe[3]),word(pipe[4])));
  968.         while pld<>nil do
  969.             with pld^ do
  970.                 begin
  971.                     if Group=pipe[7] then
  972.                         if pc=Path then
  973.                             begin
  974.                                 pc2:=PChar(Ptr(word(pipe[5]),word(pipe[6])));
  975.                                 GlobalAlloc(p2,StrLen(pc2)+1);
  976.                                 if p2<>nil then
  977.                                     begin
  978.                                         StrCopy(p2,pc2);
  979.                                         GlobalFree(Path,StrLen(Path)+1);
  980.                                         Path:=p2
  981.                                     end
  982.                             end;
  983.                     pld:=Next
  984.                 end
  985.     end;
  986.  
  987.  
  988. procedure OLGAOpenDoc(const pipe: ARRAY_8);
  989.     var answ: ARRAY_8;
  990.  
  991.     begin
  992.         {$IFDEF DEBUG}
  993.         writeln('OLGA: OLGA_OPENDOC App ',pipe[1],' Gruppe ',pipe[5]);
  994.         {$ENDIF}
  995.         OpenDoc(pipe);
  996.         answ[0]:=OLGA_ACK;
  997.         answ[1]:=apID;
  998.         answ[2]:=0;
  999.         answ[3]:=0;
  1000.         answ[4]:=0;
  1001.         answ[5]:=pipe[5];
  1002.         answ[6]:=0;
  1003.         answ[7]:=OLGA_OPENDOC;
  1004.         appl_write(pipe[1],16,@answ)
  1005.     end;
  1006.  
  1007.  
  1008. procedure OLGACloseDoc(const pipe: ARRAY_8);
  1009.     var answ: ARRAY_8;
  1010.  
  1011.     begin
  1012.         {$IFDEF DEBUG}
  1013.         writeln('OLGA: OLGA_CLOSEDOC App ',pipe[1],' Gruppe ',pipe[5]);
  1014.         {$ENDIF}
  1015.         Unlink(false,true,pipe);
  1016.         CloseDoc(true,pipe);
  1017.         answ[0]:=OLGA_ACK;
  1018.         answ[1]:=apID;
  1019.         answ[2]:=0;
  1020.         answ[3]:=0;
  1021.         answ[4]:=0;
  1022.         answ[5]:=pipe[5];
  1023.         answ[6]:=0;
  1024.         answ[7]:=OLGA_CLOSEDOC;
  1025.         appl_write(pipe[1],16,@answ)
  1026.     end;
  1027.  
  1028.  
  1029. procedure OLGALink(const pipe: ARRAY_8);
  1030.     var answ  : ARRAY_8;
  1031.         found : boolean;
  1032.         pdocd : PDocument;
  1033.         pl,pld: PLink;
  1034.         pc    : PChar;
  1035.  
  1036.     begin
  1037.         {$IFDEF DEBUG}
  1038.         writeln('OLGA: OLGA_LINK App ',pipe[1],' Gruppe ',pipe[5],'  ',PChar(Ptr(word(pipe[3]),word(pipe[4]))));
  1039.         {$ENDIF}
  1040.         found:=false;
  1041.         pdocd:=Docs;
  1042.         while pdocd<>nil do
  1043.             with pdocd^ do
  1044.                 begin
  1045.                     if apID=pipe[1] then
  1046.                         begin
  1047.                             found:=true;
  1048.                             break
  1049.                         end;
  1050.                     pdocd:=Next
  1051.                 end;
  1052.         if not(found) then OpenDoc(pipe);
  1053.         if (pipe[3]=0) and (pipe[4]=0) then answ[6]:=0
  1054.         else
  1055.             begin
  1056.                 new(pl);
  1057.                 if pl<>nil then
  1058.                     begin
  1059.                         pl^.apID:=pipe[1];
  1060.                         pl^.Group:=pipe[5];
  1061.                         pc:=PChar(Ptr(word(pipe[3]),word(pipe[4])));
  1062.                         GlobalAlloc(pl^.Path,StrLen(pc)+1);
  1063.                         if pl^.Path=nil then
  1064.                             begin
  1065.                                 dispose(pl);
  1066.                                 answ[6]:=0
  1067.                             end
  1068.                         else
  1069.                             begin
  1070.                                 StrCopy(pl^.Path,pc);
  1071.                                 pl^.Prev:=nil;
  1072.                                 pl^.Next:=nil;
  1073.                                 if Links=nil then Links:=pl
  1074.                                 else
  1075.                                     begin
  1076.                                         pld:=Links;
  1077.                                         while pld^.Next<>nil do pld:=pld^.Next;
  1078.                                         pld^.Next:=pl;
  1079.                                         pl^.Prev:=pld
  1080.                                     end;
  1081.                                 answ[6]:=1;
  1082.                                 inc(LinkCount)
  1083.                             end
  1084.                     end
  1085.                 else
  1086.                     answ[6]:=0
  1087.             end;
  1088.         answ[0]:=OLGA_ACK;
  1089.         answ[1]:=apID;
  1090.         answ[2]:=0;
  1091.         answ[3]:=pipe[3];
  1092.         answ[4]:=pipe[4];
  1093.         answ[5]:=pipe[5];
  1094.         answ[7]:=OLGA_LINK;
  1095.         appl_write(pipe[1],16,@answ)
  1096.     end;
  1097.  
  1098.  
  1099. procedure OLGAUnlink(const pipe: ARRAY_8);
  1100.     var answ: ARRAY_8;
  1101.  
  1102.     begin
  1103.         {$IFDEF DEBUG}
  1104.         writeln('OLGA: OLGA_UNLINK App ',pipe[1],' Gruppe ',pipe[5],'  ',PChar(Ptr(word(pipe[3]),word(pipe[4]))));
  1105.         {$ENDIF}
  1106.         answ[6]:=Unlink(true,true,pipe);
  1107.         answ[0]:=OLGA_ACK;
  1108.         answ[1]:=apID;
  1109.         answ[2]:=0;
  1110.         answ[3]:=pipe[3];
  1111.         answ[4]:=pipe[4];
  1112.         answ[5]:=pipe[5];
  1113.         answ[7]:=OLGA_UNLINK;
  1114.         appl_write(pipe[1],16,@answ)
  1115.     end;
  1116.  
  1117.  
  1118. procedure OLGABreakLink(const pipe: ARRAY_8);
  1119.     var answ: ARRAY_8;
  1120.         pld : PLink;
  1121.         pc  : PChar;
  1122.  
  1123.     begin
  1124.         {$IFDEF DEBUG}
  1125.         writeln('OLGA: OLGA_BREAKLINK App ',pipe[1],'  ',PChar(Ptr(word(pipe[3]),word(pipe[4]))));
  1126.         {$ENDIF}
  1127.         pld:=Links;
  1128.         answ[0]:=OLGA_LINKBROKEN;
  1129.         answ[1]:=apID;
  1130.         answ[2]:=0;
  1131.         answ[6]:=0;
  1132.         answ[7]:=0;
  1133.         pc:=PChar(Ptr(word(pipe[3]),word(pipe[4])));
  1134.         while pld<>nil do
  1135.             with pld^ do
  1136.                 begin
  1137.                     if StrIComp(pc,Path)=0 then
  1138.                         begin
  1139.                             {$IFDEF DEBUG}
  1140.                             writeln('      LinkBroken an App ',apID,' Gruppe ',Group);
  1141.                             {$ENDIF}
  1142.                             answ[3]:=integer(HiWord(Path));
  1143.                             answ[4]:=integer(LoWord(Path));
  1144.                             answ[5]:=Group;
  1145.                             appl_write(apID,16,@answ)
  1146.                         end;
  1147.                     pld:=Next
  1148.                 end;
  1149.         answ[0]:=OLGA_ACK;
  1150.         answ[3]:=pipe[3];
  1151.         answ[4]:=pipe[4];
  1152.         answ[5]:=0;
  1153.         answ[7]:=OLGA_BREAKLINK;
  1154.         appl_write(pipe[1],16,@answ)
  1155.     end;
  1156.  
  1157.  
  1158. procedure OLGAStart(const pipe: ARRAY_8);
  1159.     label _started;
  1160.  
  1161.     var answ     : ARRAY_8;
  1162.         pa       : PApp;
  1163.         pt       : PType;
  1164.         pe       : PExtension;
  1165.         tmp_drive,
  1166.         stid     : integer;
  1167.         dummy,
  1168.         stname,
  1169.         tmp_cwd,
  1170.         fname    : string;
  1171.  
  1172.     begin
  1173.         {$IFDEF DEBUG}
  1174.         write('OLGA: OLGA_START App ',pipe[1],'  ');
  1175.         case pipe[3] of
  1176.         OLS_TYPE:
  1177.             write('OLS_TYPE ',chr(hi(pipe[5])),chr(lo(pipe[5])));
  1178.         OLS_EXTENSION:
  1179.             write('OLS_EXTENSION ',chr(hi(pipe[4])),chr(lo(pipe[4])),chr(hi(pipe[5])),chr(lo(pipe[5])));
  1180.         OLS_NAME:
  1181.             write('OLS_NAME ',PChar(Ptr(word(pipe[4]),word(pipe[5]))));
  1182.         end;
  1183.         if (pipe[6]<>0) or (pipe[7]<>0) then writeln('  Cmd ',PChar(Ptr(word(pipe[6]),word(pipe[7]))))
  1184.         else
  1185.             writeln;
  1186.         {$ENDIF}
  1187.         answ[6]:=0;
  1188.         pa:=Apps;
  1189.         while pa<>nil do
  1190.             with pa^ do
  1191.                 begin
  1192.                     if apID=pipe[1] then break;
  1193.                     pa:=Next
  1194.                 end;
  1195.         if pa=nil then goto _started;
  1196.         fname:='';
  1197.         case pipe[3] of
  1198.         OLS_TYPE:
  1199.             begin
  1200.                 pt:=Types;
  1201.                 while pt<>nil do
  1202.                     with pt^ do
  1203.                         begin
  1204.                             if typ=pipe[5] then
  1205.                                 begin
  1206.                                     fname:=ExpandPath(path);
  1207.                                     break
  1208.                                 end;
  1209.                             pt:=next
  1210.                         end
  1211.             end;
  1212.         OLS_EXTENSION:
  1213.             begin
  1214.                 pe:=Extensions;
  1215.                 while pe<>nil do
  1216.                     with pe^ do
  1217.                         begin
  1218.                             if ext4=pipe[4] then
  1219.                                 if ext5=pipe[5] then
  1220.                                     begin
  1221.                                         fname:=ExpandPath(path);
  1222.                                         break
  1223.                                     end;
  1224.                             pe:=next
  1225.                         end
  1226.             end;
  1227.         OLS_NAME:
  1228.             fname:=StrPPas(Ptr(word(pipe[4]),word(pipe[5])))
  1229.         end;
  1230.         if length(fname)=0 then goto _started;
  1231.         inc(pa^.CmdCount);
  1232.         if pa^.CmdCount>CMDMAX then pa^.CmdCount:=0;
  1233.         if pa^.StartCmd[pa^.CmdCount]<>nil then GlobalFree(pa^.StartCmd[pa^.CmdCount],pa^.CmdLen[pa^.CmdCount]);
  1234.         pa^.CmdLen[pa^.CmdCount]:=length(StrPPas(Ptr(word(pipe[6]),word(pipe[7]))))+1;
  1235.         fsplit(fname,dummy,stname,tmp_cwd);
  1236.         while length(stname)<8 do stname:=stname+' ';
  1237.         for stid:=1 to 8 do stname[stid]:=upcase(stname[stid]);
  1238.         stid:=appl_find(stname);
  1239.         if stid>=0 then
  1240.             begin
  1241.                 GlobalAlloc(pa^.StartCmd[pa^.CmdCount],pa^.CmdLen[pa^.CmdCount]);
  1242.                 if pa^.StartCmd[pa^.CmdCount]=nil then goto _started;
  1243.                 StrPCopy(pa^.StartCmd[pa^.CmdCount],StrPPas(Ptr(word(pipe[6]),word(pipe[7]))));
  1244.                 answ[0]:=VA_START;
  1245.                 answ[1]:=apID;
  1246.                 answ[2]:=0;
  1247.                 answ[3]:=integer(HiWord(pa^.StartCmd[pa^.CmdCount]));
  1248.                 answ[4]:=integer(LoWord(pa^.StartCmd[pa^.CmdCount]));
  1249.                 answ[5]:=0;
  1250.                 answ[6]:=0;
  1251.                 answ[7]:=0;
  1252.                 appl_write(stid,16,@answ);
  1253.                 answ[6]:=1;
  1254.                 if (pipe[3]=OLS_TYPE) or (pipe[3]=OLS_EXTENSION) then ServerStarted(stid,pipe[1],pipe[4],pipe[5])
  1255.                 else
  1256.                     ServerStarted(stid,pipe[1],0,0)
  1257.             end
  1258.         else
  1259.             if MultiTOS or MagiX then
  1260.                 begin
  1261.                     inc(pa^.CmdLen[pa^.CmdCount]);
  1262.                     GlobalAlloc(pa^.StartCmd[pa^.CmdCount],pa^.CmdLen[pa^.CmdCount]);
  1263.                     if pa^.StartCmd[pa^.CmdCount]=nil then goto _started;
  1264.                     PChar(pa^.StartCmd[pa^.CmdCount])^:=chr(pa^.CmdLen[pa^.CmdCount]-2);
  1265.                     StrPCopy(PChar(longint(pa^.StartCmd[pa^.CmdCount])+1),StrPPas(Ptr(word(pipe[6]),word(pipe[7]))));
  1266.                     fname:=fname+#0;
  1267.                     tmp_drive:=dgetdrv;
  1268.                     dgetpath(tmp_cwd,tmp_drive+1);
  1269.                     if length(fname)>1 then
  1270.                         if fname[2]=':' then dsetdrv(ord(upcase(fname[1]))-65);
  1271.                     dsetpath(dummy+#0);
  1272.                     if MultiTOS then answ[6]:=ShelWrite(0,1,1,@fname[1],pa^.StartCmd[pa^.CmdCount])
  1273.                     else
  1274.                         answ[6]:=ShelWrite(1,1,100,@fname[1],pa^.StartCmd[pa^.CmdCount]);
  1275.                     if answ[6]=0 then
  1276.                         begin
  1277.                             dsetdrv(tmp_drive);
  1278.                             dsetpath(tmp_cwd)
  1279.                         end
  1280.                     else
  1281.                         begin
  1282.                             if (pipe[3]=OLS_TYPE) or (pipe[3]=OLS_EXTENSION) then ServerStarted(AES_pb.intout^[0],pipe[1],pipe[4],pipe[5])
  1283.                             else
  1284.                                 ServerStarted(AES_pb.intout^[0],pipe[1],0,0)
  1285.                         end
  1286.                 end;
  1287.         _started:
  1288.         answ[0]:=OLGA_ACK;
  1289.         answ[1]:=apID;
  1290.         answ[2]:=0;
  1291.         answ[3]:=pipe[3];
  1292.         answ[4]:=pipe[4];
  1293.         answ[5]:=pipe[5];
  1294.         answ[7]:=OLGA_START;
  1295.         appl_write(pipe[1],16,@answ);
  1296.         if (pipe[6]<>0) or (pipe[7]<>0) then
  1297.             begin
  1298.                 answ[3]:=0;
  1299.                 answ[4]:=pipe[6];
  1300.                 answ[5]:=pipe[7];
  1301.                 appl_write(pipe[1],16,@answ)
  1302.             end
  1303.     end;
  1304.  
  1305.  
  1306. procedure OLGAGetObjects(const pipe: ARRAY_8);
  1307.     var pa,pad: PApp;
  1308.         answ  : ARRAY_8;
  1309.         pod   : PObject;
  1310.  
  1311.     begin
  1312.         {$IFDEF DEBUG}
  1313.         write('OLGA: OLGA_GETOBJECTS App ',pipe[1],'  ');
  1314.         if pipe[3]=0 then write('first  (')
  1315.         else
  1316.             write('next  (');
  1317.         {$ENDIF}
  1318.         pa:=nil;
  1319.         pad:=Apps;
  1320.         while pad<>nil do
  1321.             begin
  1322.                 if pad^.apID=pipe[1] then
  1323.                     begin
  1324.                         pa:=pad;
  1325.                         break
  1326.                     end;
  1327.                 pad:=pad^.Next
  1328.             end;
  1329.         if pa<>nil then
  1330.             begin
  1331.                 if pipe[3]=0 then pa^.enumOLE:=Objects;
  1332.                 if pa^.enumOLE<>nil then
  1333.                     begin
  1334.                         answ[0]:=OLGA_OBJECTS;
  1335.                         answ[1]:=apID;
  1336.                         answ[2]:=0;
  1337.                         answ[3]:=0;
  1338.                         answ[4]:=pa^.enumOLE^.ext4;
  1339.                         answ[5]:=pa^.enumOLE^.ext5;
  1340.                         answ[6]:=integer(HiWord(pa^.enumOLE^.Descr));
  1341.                         answ[7]:=integer(LoWord(pa^.enumOLE^.Descr));
  1342.                         pod:=pa^.enumOLE^.Next;
  1343.                         while pod<>nil do
  1344.                             begin
  1345.                                 inc(answ[3]);
  1346.                                 pod:=pod^.Next
  1347.                             end;
  1348.                         {$IFDEF DEBUG}
  1349.                         write(answ[3],',',PChar(pa^.enumOLE^.Descr));
  1350.                         {$ENDIF}
  1351.                         appl_write(pipe[1],16,@answ);
  1352.                         pa^.enumOLE:=pa^.enumOLE^.Next
  1353.                     end
  1354.             end;
  1355.         {$IFDEF DEBUG}
  1356.         writeln(')')
  1357.         {$ENDIF}
  1358.     end;
  1359.  
  1360.  
  1361. procedure OLGAIdle(const pipe: ARRAY_8);
  1362.     var answ: ARRAY_8;
  1363.  
  1364.     begin
  1365.         {$IFDEF DEBUG}
  1366.         write('OLGA: OLGA_IDLE App ',pipe[1],' (');
  1367.         if pipe[3]=0 then writeln('reply)')
  1368.         else
  1369.             writeln('request) -> reply');
  1370.         {$ENDIF}
  1371.         if pipe[3]<>0 then
  1372.             begin
  1373.                 answ[0]:=OLGA_IDLE;
  1374.                 answ[1]:=apID;
  1375.                 answ[2]:=0;
  1376.                 answ[3]:=0;
  1377.                 answ[4]:=pipe[4];
  1378.                 answ[5]:=pipe[5];
  1379.                 answ[6]:=pipe[6];
  1380.                 answ[7]:=pipe[7];
  1381.                 appl_write(pipe[1],16,@answ)
  1382.             end
  1383.     end;
  1384.  
  1385.  
  1386. procedure OLGAActivate(const pipe: ARRAY_8);
  1387.     label _raus;
  1388.  
  1389.     var answ     : ARRAY_8;
  1390.         e4,e5,q,
  1391.         tmp_drive,
  1392.         anz      : integer;
  1393.         pc       : PChar;
  1394.         pe       : PExtension;
  1395.         tmp_cwd,
  1396.         afind,
  1397.         dummy,
  1398.         fname    : string;
  1399.  
  1400.     begin
  1401.         anz:=pipe[5];
  1402.         pc:=PChar(Ptr(word(pipe[3]),word(pipe[4])));
  1403.         {$IFDEF DEBUG}
  1404.         write('OLGA: OLGA_ACTIVATE App ',pipe[1],'  #',anz);
  1405.         if (anz<1) or (pc=nil) then writeln
  1406.         else
  1407.             begin
  1408.                 write(' (');
  1409.                 for q:=0 to (anz shl 2)-1 do write(PChar(longint(pc)+q)^);
  1410.                 writeln(')')
  1411.             end;
  1412.         {$ENDIF}
  1413.         if anz<1 then goto _raus;
  1414.         if pc=nil then goto _raus;
  1415.         repeat
  1416.             e4:=ord(pc^);
  1417.             inc(longint(pc));
  1418.             e4:=(e4 shl 8) or ord(pc^);
  1419.             inc(longint(pc));
  1420.             e5:=ord(pc^);
  1421.             inc(longint(pc));
  1422.             e5:=(e5 shl 8) or ord(pc^);
  1423.             inc(longint(pc));
  1424.             pe:=Extensions;
  1425.             fname:='';
  1426.             while pe<>nil do
  1427.                 with pe^ do
  1428.                     begin
  1429.                         if ext4=e4 then
  1430.                             if ext5=e5 then
  1431.                                 begin
  1432.                                     fname:=ExpandPath(path);
  1433.                                     break
  1434.                                 end;
  1435.                         pe:=next
  1436.                     end;
  1437.             if length(fname)>0 then
  1438.                 begin
  1439.                     fsplit(fname,dummy,afind,tmp_cwd);
  1440.                     while length(afind)<8 do afind:=afind+' ';
  1441.                     for q:=1 to 8 do afind[q]:=upcase(afind[q]);
  1442.                     q:=appl_find(afind);
  1443.                     if q>=0 then ServerStarted(q,pipe[1],e4,e5)
  1444.                     else
  1445.                         begin
  1446.                             {$IFDEF DEBUG}
  1447.                             writeln('  ...starting ',fname,' (',chr((e4 shr 8) and $00ff),chr(e4 and $00ff),chr((e5 shr 8) and $00ff),chr(e5 and $00ff),')');
  1448.                             {$ENDIF}
  1449.                             fname:=fname+#0;
  1450.                             tmp_drive:=dgetdrv;
  1451.                             dgetpath(tmp_cwd,tmp_drive+1);
  1452.                             if length(fname)>1 then
  1453.                                 if fname[2]=':' then dsetdrv(ord(upcase(fname[1]))-65);
  1454.                             dsetpath(dummy+#0);
  1455.                             if MultiTOS then answ[6]:=ShelWrite(0,1,1,@fname[1],empty)
  1456.                             else
  1457.                                 answ[6]:=ShelWrite(1,1,100,@fname[1],empty);
  1458.                             if answ[6]<>0 then
  1459.                                 begin
  1460.                                     ServerStarted(AES_pb.intout^[0],pipe[1],e4,e5);
  1461.                                     evnt_timer(1500,0)
  1462.                                 end
  1463.                             else
  1464.                                 begin
  1465.                                     dsetdrv(tmp_drive);
  1466.                                     dsetpath(tmp_cwd)
  1467.                                 end
  1468.                         end
  1469.                 end;
  1470.             dec(anz)
  1471.         until anz<=0;
  1472.         _raus:
  1473.         answ[0]:=OLGA_ACK;
  1474.         answ[1]:=apID;
  1475.         answ[2]:=0;
  1476.         answ[3]:=pipe[3];
  1477.         answ[4]:=pipe[4];
  1478.         answ[5]:=pipe[5];
  1479.         answ[6]:=0;
  1480.         answ[7]:=OLGA_ACTIVATE;
  1481.         appl_write(pipe[1],16,@answ)
  1482.     end;
  1483.  
  1484.  
  1485. procedure OLGAEmbed(const pipe: ARRAY_8);
  1486.     var tmp_cwd,
  1487.         afind,
  1488.         dummy,
  1489.         fname  : string;
  1490.         answ   : ARRAY_8;
  1491.         pe     : PExtension;
  1492.         q      : integer;
  1493.  
  1494.     begin
  1495.         {$IFDEF DEBUG}
  1496.         write('OLGA: OLGA_EMBED App ',pipe[1],' (',chr(hi(pipe[6])),chr(lo(pipe[6])),chr(hi(pipe[7])),chr(lo(pipe[7])),')  ');
  1497.         {$ENDIF}
  1498.         pe:=Extensions;
  1499.         fname:='';
  1500.         while pe<>nil do
  1501.             with pe^ do
  1502.                 begin
  1503.                     if ext4=pipe[6] then
  1504.                         if ext5=pipe[7] then
  1505.                             begin
  1506.                                 fname:=ExpandPath(path);
  1507.                                 break
  1508.                             end;
  1509.                     pe:=next
  1510.                 end;
  1511.         if length(fname)=0 then q:=-1
  1512.         else
  1513.             begin
  1514.                 fsplit(fname,dummy,afind,tmp_cwd);
  1515.                 while length(afind)<8 do afind:=afind+' ';
  1516.                 for q:=1 to 8 do afind[q]:=upcase(afind[q]);
  1517.                 q:=appl_find(afind)
  1518.             end;
  1519.         if q<0 then
  1520.             begin
  1521.                 {$IFDEF DEBUG}
  1522.                 write('error: ');
  1523.                 if length(fname)=0 then writeln('extension not assigned')
  1524.                 else
  1525.                     writeln('server not running');
  1526.                 {$ENDIF}
  1527.                 answ[0]:=OLGA_EMBEDDED;
  1528.                 answ[1]:=apID;
  1529.                 answ[2]:=0;
  1530.                 answ[3]:=pipe[3];
  1531.                 answ[4]:=pipe[4];
  1532.                 answ[5]:=pipe[5];
  1533.                 answ[6]:=0;
  1534.                 answ[7]:=0;
  1535.                 appl_write(pipe[1],16,@answ)
  1536.             end
  1537.         else
  1538.             begin
  1539.                 {$IFDEF DEBUG}
  1540.                 writeln('calling server ',q);
  1541.                 {$ENDIF}
  1542.                 answ[0]:=OLGA_EMBED;
  1543.                 answ[1]:=apID;
  1544.                 answ[2]:=0;
  1545.                 answ[3]:=pipe[3];
  1546.                 answ[4]:=pipe[4];
  1547.                 answ[5]:=pipe[5];
  1548.                 answ[6]:=0;
  1549.                 answ[7]:=pipe[1];
  1550.                 appl_write(q,16,@answ)
  1551.             end
  1552.     end;
  1553.  
  1554.  
  1555. procedure OLGARequestNotification(const pipe: ARRAY_8);
  1556.     var pn,pnd: PNote;
  1557.  
  1558.     begin
  1559.         new(pn);
  1560.         if pn<>nil then
  1561.             begin
  1562.                 Denotify(pipe[1],pipe[3],pipe[4]);
  1563.                 pn^.apID:=pipe[1];
  1564.                 pn^.ext4:=pipe[3];
  1565.                 pn^.ext5:=pipe[4];
  1566.                 pn^.Prev:=nil;
  1567.                 pn^.Next:=nil;
  1568.                 if Notes=nil then Notes:=pn
  1569.                 else
  1570.                     begin
  1571.                         pnd:=Notes;
  1572.                         while pnd^.Next<>nil do pnd:=pnd^.Next;
  1573.                         pnd^.Next:=pn;
  1574.                         pn^.Prev:=pnd
  1575.                     end
  1576.             end
  1577.     end;
  1578.  
  1579.  
  1580. procedure OLGAReleaseNotification(const pipe: ARRAY_8);
  1581.  
  1582.     begin
  1583.         {$IFDEF DEBUG}
  1584.         write('OLGA: OLGA_RELEASENOTIFICATION App ',pipe[1],' (');
  1585.         if (pipe[3]=0) and (pipe[4]=0) then writeln('all)')
  1586.         else
  1587.             writeln(chr((pipe[3] shr 8) and $00ff),chr(pipe[3] and $00ff),chr((pipe[4] shr 8) and $00ff),chr(pipe[4] and $00ff),')');
  1588.         {$ENDIF}
  1589.         Denotify(pipe[1],pipe[3],pipe[4])
  1590.     end;
  1591.  
  1592.  
  1593. procedure OLGANotified(const pipe: ARRAY_8);
  1594.     var p: pointer;
  1595.  
  1596.     begin
  1597.         p:=Ptr(word(pipe[3]),word(pipe[4]));
  1598.         {$IFDEF DEBUG}
  1599.         writeln('OLGA: OLGA_NOTIFIED App ',pipe[1],'  ',PChar(p));
  1600.         {$ENDIF}
  1601.         GlobalFree(p,StrLen(p)+1)
  1602.     end;
  1603.  
  1604.  
  1605. procedure OLGAGetSettings(const pipe: ARRAY_8);
  1606.     var answ: ARRAY_8;
  1607.  
  1608.     begin
  1609.         {$IFDEF DEBUG}
  1610.         writeln('OLGA: OLGA_GETSETTINGS App ',pipe[1]);
  1611.         {$ENDIF}
  1612.         answ[0]:=OLGA_SETTINGS;
  1613.         answ[1]:=apID;
  1614.         answ[2]:=0;
  1615.         answ[3]:=0;
  1616.         answ[4]:=0;
  1617.         answ[5]:=0;
  1618.         answ[6]:=0;
  1619.         answ[7]:=0;
  1620.         appl_write(pipe[1],16,@answ)
  1621.     end;
  1622.  
  1623.  
  1624. procedure CHExit(const pipe: ARRAY_8);
  1625.  
  1626.     begin
  1627.         {$IFDEF DEBUG}
  1628.         writeln('OLGA: CH_EXIT App ',pipe[1],'  Child ',pipe[3],' Code ',pipe[4]);
  1629.         {$ENDIF}
  1630.         ServerTerminated(pipe[3],pipe[4])
  1631.     end;
  1632.  
  1633.  
  1634. function AVPathUpdate(var pipe: ARRAY_8): boolean;
  1635.     var pad: PApp;
  1636.  
  1637.     begin
  1638.         AVPathUpdate:=false;
  1639.         pad:=Apps;
  1640.         while pad<>nil do
  1641.             with pad^ do
  1642.                 begin
  1643.                     if apID=pipe[1] then
  1644.                         begin
  1645.                             if not(bTst(Flags,OL_SERVER)) then
  1646.                                 begin
  1647.                                     pipe[0]:=OLGA_UPDATE;
  1648.                                     AVPathUpdate:=true
  1649.                                 end;
  1650.                             break
  1651.                         end;
  1652.                     pad:=Next
  1653.                 end
  1654.     end;
  1655.  
  1656.  
  1657. procedure MUKeybd(kstat,key: integer);
  1658.     var answ: ARRAY_8;
  1659.         q   : integer;
  1660.  
  1661.     begin
  1662.         if not(mbar) then exit;
  1663.         q:=menu_bar(nil,-1);
  1664.         {$IFDEF DEBUG}
  1665.         writeln('OLGA: AV_SENDKEY Stat ',kstat,' Key ',key,' -> App #',q);
  1666.         {$ENDIF}
  1667.         answ[0]:=AV_SENDKEY;
  1668.         answ[1]:=apID;
  1669.         answ[2]:=0;
  1670.         answ[3]:=kstat;
  1671.         answ[4]:=key;
  1672.         answ[5]:=0;
  1673.         answ[6]:=0;
  1674.         answ[7]:=0;
  1675.         appl_write(q,16,@answ)
  1676.     end;
  1677.  
  1678.  
  1679. procedure InitManager;
  1680.     var cookiejar: PCookie;
  1681.         tmp_drive,
  1682.         event,
  1683.         stid,
  1684.         mgxver   : integer;
  1685.         answ     : ARRAY_8;
  1686.         search,
  1687.         shutdown,
  1688.         broadcast: boolean;
  1689.         dummy,
  1690.         fname    : string;
  1691.         f        : text;
  1692.  
  1693.     procedure read_inf;
  1694.         var pal,pald : PAlias;
  1695.             pt,ptd   : PType;
  1696.             po,pod   : PObject;
  1697.             pe,ped   : PExtension;
  1698.             tmp_drive,
  1699.             stid,q   : integer;
  1700.             keyname,
  1701.             dummy    : string;
  1702.  
  1703.         begin
  1704.             while not(eof(f)) do
  1705.                 begin
  1706.                     readln(f,dummy);
  1707.                     {$IFDEF DEBUG}
  1708.                     writeln('|',dummy,'|');
  1709.                     {$ENDIF}
  1710.                     if length(dummy)>0 then
  1711.                         if dummy[1]<>';' then
  1712.                             begin
  1713.                                 if dummy[1]='[' then
  1714.                                     begin
  1715.                                         if dummy='[Extensions]' then stid:=1
  1716.                                         else if dummy='[Types]' then stid:=2
  1717.                                         else if dummy='[Applications]' then stid:=3
  1718.                                         else if dummy='[Objects]' then stid:=4
  1719.                                         else stid:=0
  1720.                                     end
  1721.                                 else
  1722.                                     case stid of
  1723.                                     1:
  1724.                                         begin
  1725.                                             new(pe);
  1726.                                             if pe=nil then continue;
  1727.                                             tmp_drive:=pos('=',dummy);
  1728.                                             pe^.ext4:=integer((ord(dummy[1]) shl 8) or ord(dummy[2]));
  1729.                                             if tmp_drive=3 then pe^.ext5:=0
  1730.                                             else
  1731.                                                 if tmp_drive=4 then pe^.ext5:=integer((ord(dummy[3]) shl 8))
  1732.                                                 else
  1733.                                                     pe^.ext5:=integer((ord(dummy[3]) shl 8) or ord(dummy[4]));
  1734.                                             pe^.path:=copy(dummy,tmp_drive+1,length(dummy)-tmp_drive);
  1735.                                             pe^.next:=nil;
  1736.                                             if Extensions=nil then Extensions:=pe
  1737.                                             else
  1738.                                                 begin
  1739.                                                     ped:=Extensions;
  1740.                                                     while ped^.next<>nil do ped:=ped^.next;
  1741.                                                     ped^.next:=pe
  1742.                                                 end
  1743.                                         end;
  1744.                                     2:
  1745.                                         begin
  1746.                                             new(pt);
  1747.                                             if pt=nil then continue;
  1748.                                             pt^.typ:=integer((ord(dummy[1]) shl 8) or ord(dummy[2]));
  1749.                                             pt^.path:=copy(dummy,4,length(dummy)-3);
  1750.                                             pt^.next:=nil;
  1751.                                             if Types=nil then Types:=pt
  1752.                                             else
  1753.                                                 begin
  1754.                                                     ptd:=Types;
  1755.                                                     while ptd^.next<>nil do ptd:=ptd^.next;
  1756.                                                     ptd^.next:=pt
  1757.                                                 end
  1758.                                         end;
  1759.                                     3:
  1760.                                         begin
  1761.                                             new(pal);
  1762.                                             if pal=nil then continue;
  1763.                                             tmp_drive:=pos('=',dummy);
  1764.                                             pal^.alias:=copy(dummy,1,tmp_drive-1);
  1765.                                             pal^.path:=copy(dummy,tmp_drive+1,length(dummy)-tmp_drive);
  1766.                                             pal^.next:=nil;
  1767.                                             if Aliases=nil then Aliases:=pal
  1768.                                             else
  1769.                                                 begin
  1770.                                                     pald:=Aliases;
  1771.                                                     while pald^.next<>nil do pald:=pald^.next;
  1772.                                                     pald^.next:=pal
  1773.                                                 end
  1774.                                         end;
  1775.                                     4:
  1776.                                         begin
  1777.                                             new(po);
  1778.                                             if po=nil then continue;
  1779.                                             tmp_drive:=pos('=',dummy);
  1780.                                             po^.ext4:=integer((ord(dummy[1]) shl 8) or ord(dummy[2]));
  1781.                                             if tmp_drive=3 then po^.ext5:=0
  1782.                                             else
  1783.                                                 if tmp_drive=4 then po^.ext5:=integer((ord(dummy[3]) shl 8))
  1784.                                                 else
  1785.                                                     po^.ext5:=integer((ord(dummy[3]) shl 8) or ord(dummy[4]));
  1786.                                             GlobalAlloc(po^.Descr,length(dummy)+1-tmp_drive);
  1787.                                             if po^.Descr=nil then continue;
  1788.                                             StrPCopy(po^.Descr,copy(dummy,tmp_drive+1,length(dummy)-tmp_drive));
  1789.                                             po^.next:=nil;
  1790.                                             if Objects=nil then Objects:=po
  1791.                                             else
  1792.                                                 begin
  1793.                                                     pod:=Objects;
  1794.                                                     while pod^.next<>nil do pod:=pod^.next;
  1795.                                                     pod^.next:=po
  1796.                                                 end
  1797.                                         end
  1798.                                     end
  1799.                             end
  1800.                 end;
  1801.             close(f)
  1802.         end;
  1803.  
  1804.     function BootDevice: char;
  1805.  
  1806.         begin
  1807.             BootDevice:=chr(supexec(bootdev))
  1808.         end;
  1809.  
  1810.     begin
  1811.         {$IFDEF DEBUG}
  1812.         writeln('OLGA aktiviert...');
  1813.         {$ENDIF}
  1814.         HeapError:=@HeapFunc;
  1815.         MemProt:=false;
  1816.         MagiX:=false;
  1817.         mgxver:=0;
  1818.       cookiejar:=PCookie(supexec(getjar));
  1819.       if cookiejar<>nil then
  1820.             while PLongint(cookiejar)^<>0 do
  1821.                 with cookiejar^ do
  1822.                     begin
  1823.                         if ID='MiNT' then MemProt:=true
  1824.                         else
  1825.                             if ID='MagX' then
  1826.                                 begin
  1827.                                     MagiX:=true;
  1828.                                     if Val<>0 then 
  1829.                                         with PMAGX_COOKIE(Val)^ do
  1830.                                             if aes_vars<>nil then
  1831.                                                 with aes_vars^ do
  1832.                                                     if (magic=-2023406815) and (magic2='MAGX') then mgxver:=version;
  1833.                                     if mgxver>=$0200 then MemProt:=true
  1834.                                 end;
  1835.                         inc(longint(cookiejar),8)
  1836.                     end;
  1837.         GEM_pb.global[0]:=0;
  1838.         apID:=appl_init;
  1839.         if GEM_pb.global[0]=0 then halt;
  1840.       if apID<0 then halt;
  1841.       wind_update(BEG_UPDATE);
  1842.         if shel_read(fname,dummy)=0 then fname:='';
  1843.         getmem(apName,length(fname)+1);
  1844.         if apName<>nil then StrPCopy(apName,fname);
  1845.         MultiTOS:=(GEM_pb.global[0]>=$0400) and (GEM_pb.global[1]=-1);
  1846.         Multitask:=(GEM_pb.global[1]<>1);
  1847.         has_agi:=(GEM_pb.global[0]>=$0400);
  1848.         if not(has_agi) then has_agi:=(mgxver>=$0200);
  1849.         if not(has_agi) then has_agi:=(appl_find('?AGI'#0#0#0#0)=0);
  1850.         if not(has_agi) then has_agi:=(wind_get(0,WF_WINX,stid,stid,stid,stid)=WF_WINX);
  1851.         if appl_xgetinfo(10,event,stid,stid,stid) then
  1852.             begin
  1853.                 shutdown:=((event and $00ff)>=9) or (mgxver>=$0300);
  1854.                 broadcast:=((event and $00ff)>=7) and not(MagiX)
  1855.             end
  1856.         else
  1857.             begin
  1858.                 shutdown:=(GEM_pb.global[0]>=$0400);
  1859.                 broadcast:=shutdown
  1860.             end;
  1861.         if appl_xgetinfo(4,stid,stid,event,stid) then search:=(event=1)
  1862.         else
  1863.             search:=(GEM_pb.global[0]>=$0400);
  1864.         if appl_xgetinfo(6,stid,stid,event,stid) then mbar:=(event=1)
  1865.         else
  1866.             mbar:=false;
  1867.         Links:=nil;
  1868.         Apps:=nil;
  1869.         Docs:=nil;
  1870.         if not(AppFlag) or MultiTOS then
  1871.             begin
  1872.                 menuID:=menu_register(apID,'  OLGA-Manager ');
  1873.                 if menuID<0 then
  1874.                     begin
  1875.                         wind_update(END_UPDATE);
  1876.                         {$IFDEF DEBUG}
  1877.                         writeln('... OLGA deaktiviert.');
  1878.                         {$ENDIF}
  1879.                         if MultiTOS then
  1880.                             begin
  1881.                                 appl_exit;
  1882.                                 halt
  1883.                             end
  1884.                         else
  1885.                             repeat
  1886.                                 evnt_timer(0,1)
  1887.                             until false
  1888.                     end;
  1889.             end;
  1890.         LinkCount:=0;
  1891.         AppCount:=0;
  1892.         DocCount:=0;
  1893.         Types:=nil;
  1894.         Extensions:=nil;
  1895.         Aliases:=nil;
  1896.         Objects:=nil;
  1897.         Notes:=nil;
  1898.         Server:=nil;
  1899.         Clients:=nil;
  1900.         GlobalAlloc(empty,16);
  1901.         if empty<>nil then PChar(empty)^:=#0;
  1902.         stid:=0;
  1903.         dummy:=getenv('HOME');
  1904.         if length(dummy)>0 then
  1905.             begin
  1906.                 if dummy[length(dummy)]<>'\' then dummy:=dummy+'\';
  1907.                 {$IFDEF DEBUG}
  1908.                 writeln(dummy+'defaults\olga.inf (?)');
  1909.                 {$ENDIF}
  1910.                 assign(f,dummy+'defaults\olga.inf');
  1911.                 reset(f);
  1912.                 if ioresult=0 then read_inf
  1913.                 else
  1914.                     begin
  1915.                         {$IFDEF DEBUG}
  1916.                         writeln(dummy+'olga.inf (?)');
  1917.                         {$ENDIF}
  1918.                         assign(f,dummy+'olga.inf');
  1919.                         reset(f);
  1920.                         if ioresult=0 then read_inf
  1921.                         else
  1922.                             begin
  1923.                                 {$IFDEF DEBUG}
  1924.                                 writeln(BootDevice+':\olga.inf (?)');
  1925.                                 {$ENDIF}
  1926.                                 assign(f,BootDevice+':\olga.inf');
  1927.                                 reset(f);
  1928.                                 if ioresult=0 then read_inf
  1929.                                 else
  1930.                                     begin
  1931.                                         {$IFDEF DEBUG}
  1932.                                         writeln('olga.inf (?)');
  1933.                                         {$ENDIF}
  1934.                                         assign(f,'olga.inf');
  1935.                                         reset(f);
  1936.                                         if ioresult=0 then read_inf
  1937.                                     end
  1938.                             end
  1939.                     end
  1940.             end
  1941.         else
  1942.             begin
  1943.                 {$IFDEF DEBUG}
  1944.                 writeln(BootDevice+':\olga.inf (?)');
  1945.                 {$ENDIF}
  1946.                 assign(f,BootDevice+':\olga.inf');
  1947.                 reset(f);
  1948.                 if ioresult=0 then read_inf
  1949.                 else
  1950.                     begin
  1951.                         {$IFDEF DEBUG}
  1952.                         writeln('olga.inf (?)');
  1953.                         {$ENDIF}
  1954.                         assign(f,'olga.inf');
  1955.                         reset(f);
  1956.                         if ioresult=0 then read_inf
  1957.                     end
  1958.             end;
  1959.         {$IFDEF DEBUG}
  1960.         writeln;
  1961.         {$ENDIF}
  1962.         termflag:=false;
  1963.         wind_update(END_UPDATE);
  1964.         Psignal(SIGTERM,@SigHandler);
  1965.         Psignal(SIGQUIT,@SigHandler);
  1966.         if not(Multitask) then
  1967.             begin
  1968.                 form_alert(1,'[0][OLGA v'+OLGAVersionStr+'  Rev '+OLGARevision+' ('+OLGADate+') | |Bitte unter einem|Multitasking-Betriebssystem|verwenden.][   OK   ]');
  1969.                 if AppFlag then
  1970.                     begin
  1971.                         {$IFDEF DEBUG}
  1972.                         writeln('... OLGA deaktiviert.');
  1973.                         {$ENDIF}
  1974.                         appl_exit;
  1975.                         halt
  1976.                     end
  1977.             end;
  1978.         if shutdown then ShelWrite(9,1,0,nil,nil);
  1979.         answ[0]:=OLE_NEW;
  1980.         answ[1]:=apID;
  1981.         answ[2]:=0;
  1982.         answ[3]:=OLGAFlags;
  1983.         answ[4]:=OLGAProtocol;
  1984.         answ[5]:=0;
  1985.         answ[6]:=0;
  1986.         answ[7]:=OLGAVersion;
  1987.         if broadcast then
  1988.             begin
  1989.                 with AES_pb do
  1990.                     begin
  1991.                         control^[0]:=121;
  1992.                         control^[1]:=3;
  1993.                         control^[2]:=1;
  1994.                         control^[3]:=2;
  1995.                         control^[4]:=0;
  1996.                         intin^[0]:=7;
  1997.                         intin^[1]:=0;
  1998.                         intin^[2]:=0;
  1999.                         addrin^[0]:=@answ;
  2000.                         addrin^[1]:=nil
  2001.                     end;
  2002.                 _crystal(@AES_pb)
  2003.             end
  2004.         else
  2005.             if search then
  2006.                 begin
  2007.                     stid:=appl_search(0,dummy,tmp_drive,event);
  2008.                     while stid=1 do
  2009.                         begin
  2010.                             if (tmp_drive<>1) and (event<>apID) then appl_write(event,16,@answ);
  2011.                             stid:=appl_search(1,dummy,tmp_drive,event)
  2012.                         end
  2013.                 end
  2014.     end;
  2015.  
  2016.  
  2017. procedure EventLoop;
  2018.     label _again;
  2019.     
  2020.     var dummy,
  2021.         event,
  2022.         kstat,
  2023.         key  : integer;
  2024.         pipe : ARRAY_8;
  2025.  
  2026.     begin
  2027.         repeat
  2028.             event:=evnt_multi(MU_MESAG or MU_TIMER or MU_KEYBD,0,0,0,0,0,0,0,0,0,0,0,0,0,pipe,1000,0,dummy,dummy,dummy,kstat,key,dummy);
  2029.             _again:
  2030.             if bTst(event,MU_MESAG) then
  2031.                 case pipe[0] of
  2032.                 AC_OPEN:
  2033.                     form_alert(1,'[0][OLGA v'+OLGAVersionStr+'  Rev '+OLGARevision+' ('+OLGADate+') |    by Thomas_Much@ka2.maus.de|'+ltoa(AppCount)+' OLGA-Application(s)|'+ltoa(DocCount)+' Document(s)|'+ltoa(LinkCount)+' Link(s)][   OK   ]');
  2034.                 AP_TERM:
  2035.                     termflag:=true;
  2036.                 AV_PATH_UPDATE:
  2037.                     if AVPathUpdate(pipe) then goto _again;
  2038.                 OLE_INIT:
  2039.                     OLEInit(pipe);
  2040.                 OLE_EXIT:
  2041.                     OLEExit(pipe);
  2042.                 OLGA_UPDATE:
  2043.                     OLGAUpdate(pipe);
  2044.                 OLGA_RENAME:
  2045.                     OLGARename(pipe);
  2046.                 OLGA_LINKRENAMED:
  2047.                     OLGALinkRenamed(pipe);
  2048.                 OLGA_OPENDOC:
  2049.                     OLGAOpenDoc(pipe);
  2050.                 OLGA_CLOSEDOC:
  2051.                     OLGACloseDoc(pipe);
  2052.                 OLGA_LINK:
  2053.                     OLGALink(pipe);
  2054.                 OLGA_UNLINK:
  2055.                     OLGAUnlink(pipe);
  2056.                 OLGA_BREAKLINK:
  2057.                     OLGABreakLink(pipe);
  2058.                 OLGA_START:
  2059.                     OLGAStart(pipe);
  2060.                 OLGA_GETOBJECTS:
  2061.                     OLGAGetObjects(pipe);
  2062.                 OLGA_IDLE:
  2063.                     OLGAIdle(pipe);
  2064.                 OLGA_ACTIVATE:
  2065.                     OLGAActivate(pipe);
  2066.                 OLGA_EMBED:
  2067.                     OLGAEmbed(pipe);
  2068.                 OLGA_REQUESTNOTIFICATION:
  2069.                     OLGARequestNotification(pipe);
  2070.                 OLGA_RELEASENOTIFICATION:
  2071.                     OLGAReleaseNotification(pipe);
  2072.                 OLGA_NOTIFIED:
  2073.                     OLGANotified(pipe);
  2074.                 OLGA_GETSETTINGS:
  2075.                     OLGAGetSettings(pipe);
  2076.                 CH_EXIT:
  2077.                     CHExit(pipe)
  2078.                 end;
  2079.             if bTst(event,MU_KEYBD) then MUKeybd(kstat,key)
  2080.         until termflag
  2081.     end;
  2082.  
  2083.  
  2084. procedure ExitManager;
  2085.     var answ: ARRAY_8;
  2086.         pad : PApp;
  2087.  
  2088.     begin
  2089.         {$IFDEF DEBUG}
  2090.         writeln('... OLGA deaktiviert.');
  2091.         {$ENDIF}
  2092.         answ[0]:=OLE_EXIT;
  2093.         answ[1]:=apID;
  2094.         answ[2]:=0;
  2095.         answ[3]:=0;
  2096.         answ[4]:=0;
  2097.         answ[5]:=0;
  2098.         answ[6]:=0;
  2099.         answ[7]:=0;
  2100.         pad:=Apps;
  2101.         while pad<>nil do
  2102.             begin
  2103.                 appl_write(pad^.apID,16,@answ);
  2104.                 pad:=pad^.Next
  2105.             end;
  2106.         appl_exit
  2107.     end;
  2108.  
  2109.  
  2110. begin
  2111.     InitManager;
  2112.     EventLoop;
  2113.     ExitManager
  2114. end.